﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace oled
{
    /*
    partial class OLED_Drive
    {

        //生成一个窗口
        private Rectangle Set_Windows(int x, int y, int sx, int sy)
        {
            Rectangle Framework = new Rectangle(new Point(x, y), new Size(sx, sy));

            return Framework;
        }

        #region 顶层驱动

        #region 内部调用
        private void Bitmap_point(int x, int y, Bitmap oled, Color color)
        {
            x *= OLED_DPI;
            y *= OLED_DPI;
            int tx = x, ty = y, dpi = OLED_DPI;
            if (PixelSytle == true)
            {
                dpi = OLED_DPI - 1;
            }

            for (int heitht = 0; heitht < dpi; heitht++, ty++, tx = x)
            {
                for (int width = 0; width < dpi; width++, tx++)
                {
                    oled.SetPixel(tx, ty, color);
                }
            }
        }
        private void VH_Mode(int x, int y, Byte data, Bitmap oled)
        {
            if (x >= OLED_Width || y >= OLED_Height) return;

            bool[] points = Byte_order.Bool_Array(data, Bit_Order);

            if (points.Length <= 0) return;

            //Clear(x, y, 1, 8, oled);

            for (int offset = 0; offset < 8; offset++)
            {
                //绘制点到 bitmap
                if (points[offset] == true) Bitmap_point(x, y + offset, oled, Color.White);
                //隐射此点信息到buffer
                oled_map[y + offset, x] = points[offset];
            }
        }
        private void HV_Mode(int x, int y, Byte data, Bitmap oled)
        {
            if (x >= OLED_Width || y >= OLED_Height) return;

            bool[] points = Byte_order.Bool_Array(data, Bit_Order);

            if (points.Length <= 0) return;

            //Clear(x, y, 8, 1, oled);

            for (int offset = 0; offset < 8; offset++)
            {
                if (points[offset] == true)
                {
                    Bitmap_point(x + offset, y, oled, Color.White);
                }
                oled_map[y, x + offset] = points[offset];
            }
        }
        private void DrawByte(int x, int y, byte data, Bitmap oled)
        {
            switch (Scan_Mode)
            {
                //case Oled_Mode.Vertical_scan:
                //    break;
                //case Oled_Mode.Horizontal_scan:
                //    break;
                case OLED_Scan_Mode.VertiByte_HoriScan:
                    VH_Mode(x, y, data, oled);
                    break;
                case OLED_Scan_Mode.HoriByte_Vertiscan:
                    HV_Mode(x, y, data, oled);
                    break;
                default:
                    break;
            }
        }
        #endregion

        public void ShowChar(int x, int y, byte data, Bitmap oled)
        {
            int index = data - ' ';

            index *= 6;//F6X8

            for (int i = 0; i < 6; i++)
            {
                DrawByte(x + i, y, Fonts.F6X8[index + i], oled);
            }
        }
        public void ShowString(int x, int y, string text, Bitmap oled)
        {
            Byte[] data = System.Text.Encoding.Default.GetBytes(text);
            for (int loop = 0; loop < text.Length; loop++)
            {
                ShowChar(x, y, data[loop], oled);
                x += 6;
            }
        }
        //显示bmp
        public void ShowBMP(int Pos_x, int Pos_y, byte[] bmp, int height, int width, Bitmap oled)
        {

            List<Rectangle> PointList = new List<Rectangle>();
            Byte[] line = new Byte[width];
            OLED_BYTE oled_points;
            int loop = height / 8;

            if (Pos_x >= OLED_Width || Pos_y >= OLED_Height) return;

            PointList.Clear();

            if (height % 8 != 0) loop++;

            for (int page = 1, y = 0; page <= loop; page++, y += 8)
            {
                Array.Copy(bmp, width * (page - 1), line, 0, width);

                for (int x = 0; x < width; x++)
                {
                    oled_points = new OLED_BYTE(Pos_x + x, Pos_y + y, line[x]);
                    PointList.AddRange(VH_GetPoints(oled_points));
                    Byte_ToMap(Pos_x, Pos_y, line[x], x);
                }
            }

            Rectangle[] points = PointList.ToArray();

            if (points.Length != 0)
            {
                Graphics Graphic = Graphics.FromImage(oled);
                Clear(Pos_x, Pos_y, width, height, oled);
                Brush brush = new SolidBrush(Color.FromArgb(255, 255, 255));
                Graphic.FillRectangles(brush, points);
            }
        }
        public void Clear(Bitmap oled)
        {
            Graphics Graphic = Graphics.FromImage(oled);
            Graphic.Clear(Color.Black);
        }
        public void Clear(int x, int y, int sx, int sy, Bitmap oled)
        {
            Brush brush = new SolidBrush(Color.Black);

            Rectangle windows = Set_Windows(x * OLED_DPI, y * OLED_DPI, sx * OLED_DPI, sy * OLED_DPI);
            Graphics Graphic = Graphics.FromImage(oled);
            Graphic.FillRectangle(brush, windows);
        }

        #endregion

    }
    */
}
